/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.java.service;

import com.java.dao.SachDAO;
import com.java.mapbean.Sach;
import java.util.List;
import org.springframework.stereotype.Service;

/**
 *
 * @author quannq
 */
@Service
public class SachService extends SachDAO {

    public void saveSach(Sach sach) {
        save(sach);
    }

    public void updateSach(Sach sach) {
        update(sach);
    }

    public List<Sach> getAll() {
        return findAll();
    }

    public Sach findId(int id) {
        return findById(id);
    }

    public List<Sach> getAll(int matl1, int matl2, int matl3, int page) {
        int begin = page * 10 - 10;
        return findAll(matl1, matl2, matl3, begin);
    }

    public int pageAll(int matl1, int matl2, int matl3) {
        return count(matl1, matl2, matl3) % 10 == 0 ? count(matl1, matl2, matl3) / 10 : (count(matl1, matl2, matl3) / 10) + 1;
    }

    public int countAll(int matl1, int matl2, int matl3) {
        return count(matl1, matl2, matl3);
    }
//begin khuyen mai

    public List<Sach> khuyenMai4(int page) {
        int begin = page * 4 - 4;
        return find4KM(begin);
    }

    public List<Sach> khuyenMai10(int page) {
        int begin = page * 10 - 10;
        return findKM(begin);
    }

    public int pageKM(int per) {
        return countKM() % per == 0 ? countKM() / per : (countKM() / per) + 1;
    }

    public int countSachKM() {
        return countKM();
    }

    public List<Sach> khuyenMai4(int matl1, int page) {
        int begin = page * 4 - 4;
        return find4KM(matl1, begin);
    }

    public List<Sach> khuyenMai10(int matl1, int page) {
        int begin = page * 10 - 10;
        return findKM(matl1, begin);
    }

    public int pageKM(int matl1, int per) {
        return countKM(matl1) % per == 0 ? countKM(matl1) / per : (countKM(matl1) / per) + 1;
    }

    public int countSachKM(int matl1) {
        return countKM(matl1);
    }

    public List<Sach> khuyenMai4(int matl1, int matl2, int page) {
        int begin = page * 4 - 4;
        return find4KM(matl1, matl2, begin);
    }

    public List<Sach> khuyenMai10(int matl1, int matl2, int page) {
        int begin = page * 10 - 10;
        return findKM(matl1, matl2, begin);
    }

    public int pageKM(int matl1, int matl2, int per) {
        return countKM(matl1, matl2) % per == 0 ? countKM(matl1, matl2) / per : (countKM(matl1, matl2) / per) + 1;
    }

    public int countSachKM(int matl1, int matl2) {
        return countKM(matl1, matl2);
    }
//end khuyen mai

//begin khac
    public List<Sach> khac4(int page) {
        int begin = page * 4 - 4;
        return find4Khac(begin);
    }

    public List<Sach> khac10(int page) {
        int begin = page * 10 - 10;
        return findKhac(begin);
    }

    public int pageKhac(int per) {
        return countKhac() % per == 0 ? countKhac() / per : (countKhac() / per) + 1;
    }

    public int countSachKhac() {
        return countKhac();
    }

    public List<Sach> khac4(int matl1, int page) {
        int begin = page * 4 - 4;
        return find4Khac(matl1, begin);
    }

    public List<Sach> khac10(int matl1, int page) {
        int begin = page * 10 - 10;
        return findKhac(matl1, begin);
    }

    public int pageKhac(int matl1, int per) {
        return countKhac(matl1) % per == 0 ? countKhac(matl1) / per : (countKhac(matl1) / per) + 1;
    }

    public int countSachKhac(int matl1) {
        return countKhac(matl1);
    }

    public List<Sach> khac4(int matl1, int matl2, int page) {
        int begin = page * 4 - 4;
        return find4Khac(matl1, matl2, begin);
    }

    public List<Sach> khac10(int matl1, int matl2, int page) {
        int begin = page * 10 - 10;
        return findKhac(matl1, matl2, begin);
    }

    public int pageKhac(int matl1, int matl2, int per) {
        return countKhac(matl1, matl2) % per == 0 ? countKhac(matl1, matl2) / per : (countKhac(matl1, matl2) / per) + 1;
    }

    public int countSachKhac(int matl1, int matl2) {
        return countKhac(matl1, matl2);
    }
    //end khac

    //begin Search
    public List<Sach> searchSach(int matl1, String noidung, int page) {
        int begin = page * 10 - 10;
        return search(matl1, noidung, begin);
    }

    public int pageSearch(int matl1, String noidung, int per) {
        return countSearch(matl1, noidung) % per == 0 ? countSearch(matl1, noidung) / per : countSearch(matl1, noidung) / per + 1;
    }

    public int countSachSearch(int matl1, String noidung) {
        return countSearch(matl1, noidung);
    }
    //end Search
}
